/**
 * dateTimeStamp是评论的发送时间   2020-01-12 20:10:15 这样的形式
 * @param dateTimeStamp
 * @returns {string}
 */
export function timeAgo(dateTimeStamp) {

	let result = "";
	let minute = 1000 * 60; //把分，时，天，周，半个月，一个月用毫秒表示
	let hour = minute * 60;
	let day = hour * 24;
	let week = day * 7;
	let halfamonth = day * 15;
	let month = day * 30;
	let now = new Date().getTime(); //获取当前时间毫秒
	console.log(now);
	dateTimeStamp = dateTimeStamp.substring(0, 18);

	/* =========== */

	//必须把日期'-'转为'/'
	dateTimeStamp = dateTimeStamp.replace(/-/g, '/');
	console.log(dateTimeStamp);
	let datetime = new Date(dateTimeStamp);
	console.log(datetime);
	let timestamp = datetime.getTime();



	let diffValue = now - timestamp; //时间差
	console.log('diffValue' + diffValue);

	if (diffValue < 0) {
		return result;
	}
	let minC = diffValue / minute; //计算时间差的分，时，天，周，月
	console.log("minute" + minute);
	console.log('minC' + minC);
	let hourC = diffValue / hour;
	console.log('hourC' + hourC);
	let dayC = diffValue / day;
	console.log('dayC' + dayC);
	let weekC = diffValue / week;
	console.log('weekC' + weekC);
	let monthC = diffValue / month;
	console.log('monthC' + monthC);
	if (monthC >= 1 && monthC <= 3) {
		result = " " + parseInt(monthC) + "月前"
	} else if (weekC >= 1 && weekC <= 3) {
		result = " " + parseInt(weekC) + "周前"
	} else if (dayC >= 1 && dayC <= 6) {
		result = " " + parseInt(dayC) + "天前"
	} else if (hourC >= 1 && hourC < 24) {
		result = " " + parseInt(hourC) + "小时前"
	} else if (minC >= 1 && minC < 60) {
		result = " " + parseInt(minC) + "分钟前"
	} else if (diffValue >= 0 && diffValue <= minute) {
		result = "刚刚"
	} else {
		let Nyear = datetime.getFullYear();
		console.log(Nyear);
		let Nmonth = datetime.getMonth() + 1 < 10 ? "0" + (datetime.getMonth() + 1) : datetime.getMonth() + 1;
		let Ndate = datetime.getDate() < 10 ? "0" + datetime.getDate() : datetime.getDate();
		let Nhour = datetime.getHours() < 10 ? "0" + datetime.getHours() : datetime.getHours();
		let Nminute = datetime.getMinutes() < 10 ? "0" + datetime.getMinutes() : datetime.getMinutes();
		let Nsecond = datetime.getSeconds() < 10 ? "0" + datetime.getSeconds() : datetime.getSeconds();
		result = Nyear + "-" + Nmonth + "-" + Ndate
		console.log(result);
	}
	return result;
}


export function jumpTo(Url) {
	uni.navigateTo({
		url: Url
	})
}
